package com.tencent.smtt.sdk;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import com.tencent.smtt.sdk.TbsListener;
import com.tencent.smtt.utils.TbsLog;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import okhttp3.internal.connection.RealConnection;

/* loaded from: classes2.dex */
public class TbsShareManager {
    private static Context a = null;
    private static boolean b = false;
    private static String c = null;
    private static String d = null;
    private static int e = 0;
    private static String f = null;
    private static boolean g = false;
    private static boolean h = false;
    private static String i = null;
    private static boolean j = false;
    private static boolean k = false;
    public static boolean mHasQueryed = false;

    public static int a(Context context, boolean z) {
        b(context, z);
        return e;
    }

    public static String a() {
        return d;
    }

    public static void a(Context context) {
        TbsLog.i("TbsShareManager", "shareTbsCore #1");
        try {
            TbsLinuxToolsJni tbsLinuxToolsJni = new TbsLinuxToolsJni(context);
            a(context, tbsLinuxToolsJni, am.a().r(context));
            File s = am.a().s(context);
            TbsLog.i("TbsShareManager", "shareTbsCore tbsShareDir is " + s.getAbsolutePath());
            tbsLinuxToolsJni.a(s.getAbsolutePath(), "755");
        } catch (Throwable th) {
            TbsLog.i("TbsShareManager", "shareTbsCore tbsShareDir error is " + th.getMessage() + " ## " + th.getCause());
            th.printStackTrace();
        }
    }

    private static void a(Context context, TbsLinuxToolsJni tbsLinuxToolsJni, File file) {
        File[] listFiles;
        TbsLog.i("TbsShareManager", "shareAllDirsAndFiles #1");
        if (file != null && file.exists() && file.isDirectory()) {
            TbsLog.i("TbsShareManager", "shareAllDirsAndFiles dir is " + file.getAbsolutePath());
            tbsLinuxToolsJni.a(file.getAbsolutePath(), "755");
            for (File file2 : file.listFiles()) {
                if (file2.isFile()) {
                    int indexOf = file2.getAbsolutePath().indexOf(".so");
                    String absolutePath = file2.getAbsolutePath();
                    if (indexOf > 0) {
                        tbsLinuxToolsJni.a(absolutePath, "755");
                    } else {
                        tbsLinuxToolsJni.a(absolutePath, "644");
                    }
                } else if (file2.isDirectory()) {
                    a(context, tbsLinuxToolsJni, file2);
                } else {
                    TbsLog.e("TbsShareManager", "unknown file type.", true);
                }
            }
        }
    }

    public static void b(Context context) {
        try {
            a(context, new TbsLinuxToolsJni(context), am.a().q(context));
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    static boolean b(Context context, boolean z) {
        if (i(context)) {
            return true;
        }
        if (z) {
            QbSdk.a(context, "TbsShareManager::isShareTbsCoreAvailable forceSysWebViewInner!");
            return false;
        }
        return false;
    }

    public static String c(Context context) {
        j(context);
        return d;
    }

    private static void c(Context context, boolean z) {
        BufferedOutputStream bufferedOutputStream;
        File tbsShareFile;
        Properties properties;
        BufferedInputStream bufferedInputStream = null;
        try {
            tbsShareFile = getTbsShareFile(context, "core_info");
        } catch (Throwable th) {
            th = th;
            bufferedOutputStream = null;
        }
        if (tbsShareFile == null) {
            return;
        }
        BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(tbsShareFile));
        try {
            properties = new Properties();
            properties.load(bufferedInputStream2);
            properties.setProperty("core_disabled", String.valueOf(false));
            if (z) {
                String absolutePath = am.a().r(context).getAbsolutePath();
                String packageName = context.getApplicationContext().getPackageName();
                int b2 = com.tencent.smtt.utils.b.b(context);
                properties.setProperty("core_packagename", packageName);
                properties.setProperty("core_path", absolutePath);
                properties.setProperty("app_version", String.valueOf(b2));
            }
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(tbsShareFile));
        } catch (Throwable th2) {
            th = th2;
            bufferedOutputStream = null;
        }
        try {
            properties.store(bufferedOutputStream, (String) null);
            try {
                bufferedInputStream2.close();
            } catch (Exception unused) {
            }
        } catch (Throwable th3) {
            th = th3;
            bufferedInputStream = bufferedInputStream2;
            try {
                th.printStackTrace();
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (Exception unused2) {
                    }
                }
                if (bufferedOutputStream == null) {
                    return;
                }
                bufferedOutputStream.close();
            } catch (Throwable th4) {
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (Exception unused3) {
                    }
                }
                if (bufferedOutputStream != null) {
                    try {
                        bufferedOutputStream.close();
                    } catch (Exception unused4) {
                    }
                }
                throw th4;
            }
        }
        try {
            bufferedOutputStream.close();
        } catch (Exception unused5) {
        }
    }

    public static int d(Context context) {
        return a(context, true);
    }

    public static Context e(Context context) {
        j(context);
        String str = f;
        if (str != null) {
            Context packageContext = getPackageContext(context, str);
            if (am.a().f(packageContext)) {
                return packageContext;
            }
            return null;
        }
        return null;
    }

    public static synchronized String f(Context context) {
        BufferedInputStream bufferedInputStream;
        synchronized (TbsShareManager.class) {
            try {
                File tbsShareFile = getTbsShareFile(context, "core_info");
                if (tbsShareFile == null) {
                    return null;
                }
                bufferedInputStream = new BufferedInputStream(new FileInputStream(tbsShareFile));
                try {
                    Properties properties = new Properties();
                    properties.load(bufferedInputStream);
                    String property = properties.getProperty("core_packagename", "");
                    if ("".equals(property)) {
                        try {
                            bufferedInputStream.close();
                        } catch (Exception unused) {
                        }
                        return null;
                    }
                    try {
                        bufferedInputStream.close();
                    } catch (Exception unused2) {
                    }
                    return property;
                } catch (Throwable th) {
                    th = th;
                    th.printStackTrace();
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (Exception unused3) {
                        }
                    }
                    return null;
                }
            } catch (Throwable th2) {
                th = th2;
                bufferedInputStream = null;
            }
        }
    }

    public static int findCoreForThirdPartyApp(Context context) {
        String str;
        n(context);
        TbsLog.i("TbsShareManager", "core_info mAvailableCoreVersion is " + e + " mAvailableCorePath is " + d + " mSrcPackageName is " + f);
        if (f == null) {
            TbsLog.e("TbsShareManager", "mSrcPackageName is null !!!");
        }
        String str2 = f;
        if (str2 == null || !str2.equals("AppDefined")) {
            if (!k(context) && !l(context)) {
                e = 0;
                d = null;
                f = null;
                str = "core_info error checkCoreInfo is false and checkCoreInOthers is false ";
                TbsLog.i("TbsShareManager", str);
            }
        } else if (e != am.a().a(c)) {
            e = 0;
            d = null;
            f = null;
            str = "check AppDefined core is error src is " + e + " dest is " + am.a().a(c);
            TbsLog.i("TbsShareManager", str);
        }
        if (e > 0) {
            ApplicationInfo applicationInfo = context.getApplicationInfo();
            if ((!("com.tencent.android.qqdownloader".equals(applicationInfo.packageName) || "com.jd.jrapp".equals(applicationInfo.packageName)) ? QbSdk.a(context, e) : false) || g) {
                e = 0;
                d = null;
                f = null;
                TbsLog.i("TbsShareManager", "core_info error QbSdk.isX5Disabled ");
            }
        }
        return e;
    }

    public static boolean forceLoadX5FromTBSDemo(Context context) {
        int sharedTbsCoreVersion;
        if (context == null || am.a().a(context, (File[]) null) || (sharedTbsCoreVersion = getSharedTbsCoreVersion(context, TbsConfig.APP_DEMO)) <= 0) {
            return false;
        }
        writeProperties(context, Integer.toString(sharedTbsCoreVersion), TbsConfig.APP_DEMO, am.a().r(getPackageContext(context, TbsConfig.APP_DEMO)).getAbsolutePath(), "1");
        return true;
    }

    public static void forceToLoadX5ForThirdApp(Context context, boolean z) {
        File s;
        int a2;
        try {
            if (!isThirdPartyApp(context) || QbSdk.getOnlyDownload() || (s = am.a().s(context)) == null) {
                return;
            }
            if (z && new File(s, "core_info").exists()) {
                return;
            }
            if (c != null && (a2 = am.a().a(c)) > 0) {
                d = c;
                f = "AppDefined";
                e = a2;
                writeProperties(context, Integer.toString(a2), f, d, Integer.toString(1));
                return;
            }
            TbsLog.i("TbsShareManager", "forceToLoadX5ForThirdApp #1");
            int h2 = h(context);
            int j2 = am.a().j(context);
            TbsLog.i("TbsShareManager", "forceToLoadX5ForThirdApp coreVersionFromConfig is " + h2);
            TbsLog.i("TbsShareManager", "forceToLoadX5ForThirdApp coreVersionFromCoreShare is " + j2);
            String[] coreProviderAppList = getCoreProviderAppList();
            for (String str : coreProviderAppList) {
                int coreShareDecoupleCoreVersion = getCoreShareDecoupleCoreVersion(context, str);
                if (coreShareDecoupleCoreVersion >= h2 && coreShareDecoupleCoreVersion >= j2 && coreShareDecoupleCoreVersion > 0) {
                    d = am.a().c(context, getPackageContext(context, str)).getAbsolutePath();
                    f = str;
                    e = coreShareDecoupleCoreVersion;
                    if (QbSdk.canLoadX5FirstTimeThirdApp(context)) {
                        int b2 = com.tencent.smtt.utils.b.b(context);
                        TbsLog.i("TbsShareManager", "forceToLoadX5ForThirdApp #2");
                        writeProperties(context, Integer.toString(e), f, d, Integer.toString(b2));
                        return;
                    }
                    e = 0;
                    d = null;
                    f = null;
                }
            }
            for (String str2 : coreProviderAppList) {
                int sharedTbsCoreVersion = getSharedTbsCoreVersion(context, str2);
                if (sharedTbsCoreVersion >= h2 && sharedTbsCoreVersion >= j2 && sharedTbsCoreVersion > 0) {
                    d = am.a().b(context, getPackageContext(context, str2)).getAbsolutePath();
                    f = str2;
                    e = sharedTbsCoreVersion;
                    if (QbSdk.canLoadX5FirstTimeThirdApp(context)) {
                        writeProperties(context, Integer.toString(e), f, d, Integer.toString(com.tencent.smtt.utils.b.b(context)));
                        return;
                    }
                    e = 0;
                    d = null;
                    f = null;
                }
            }
            if (QbSdk.mDisableUseHostBackupCore) {
                return;
            }
            if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
                TbsLog.i("TbsShareManager", "in mainthread so do not find host backup core to install ");
                return;
            }
            for (String str3 : coreProviderAppList) {
                int backupCoreVersion = getBackupCoreVersion(context, str3);
                if (backupCoreVersion >= h2 && backupCoreVersion >= j2 && backupCoreVersion > 0) {
                    TbsLog.i("TbsShareManager", "find host backup core to unzip forceload coreVersion is " + backupCoreVersion + " packageName is " + str3);
                    boolean a3 = am.a().a(context, getBackupCoreFile(context, str3));
                    TbsLog.i("TbsShareManager", "find host backup core to unzip forceload after unzip ");
                    if (a3) {
                        am.a().a(context, backupCoreVersion);
                        am.a().c(context, true);
                        return;
                    }
                    return;
                }
                int backupDecoupleCoreVersion = getBackupDecoupleCoreVersion(context, str3);
                if (backupDecoupleCoreVersion >= h2 && backupDecoupleCoreVersion >= j2 && backupDecoupleCoreVersion > 0) {
                    TbsLog.i("TbsShareManager", "find host backup core to unzip forceload decouple coreVersion is " + backupDecoupleCoreVersion + " packageName is " + str3);
                    boolean a4 = am.a().a(context, getBackupCoreFile(context, str3));
                    TbsLog.i("TbsShareManager", "find host backup decouple core to unzip forceload after unzip ");
                    if (a4) {
                        am.a().a(context, backupDecoupleCoreVersion);
                        am.a().c(context, true);
                        return;
                    }
                    return;
                }
            }
        } catch (Exception unused) {
        }
    }

    public static String g(Context context) {
        try {
            n(context);
            String str = d;
            if (str != null && !TextUtils.isEmpty(str)) {
                return d + File.separator + "res.apk";
            }
            return null;
        } catch (Throwable th) {
            Log.e("", "getTbsResourcesPath exception: " + Log.getStackTraceString(th));
            return null;
        }
    }

    public static File getBackupCoreFile(Context context, String str) {
        try {
            return new File(new File(com.tencent.smtt.utils.j.a(getPackageContext(context, str), 4)), "x5.tbs.org");
        } catch (Throwable unused) {
            return null;
        }
    }

    public static int getBackupCoreVersion(Context context, String str) {
        try {
            return com.tencent.smtt.utils.a.b(new File(new File(com.tencent.smtt.utils.j.a(getPackageContext(context, str), 4)), "x5.tbs.org"));
        } catch (Throwable unused) {
            return 0;
        }
    }

    public static File getBackupDecoupleCoreFile(Context context, String str) {
        try {
            return new File(new File(com.tencent.smtt.utils.j.a(getPackageContext(context, str), 4)), "x5.tbs.decouple");
        } catch (Throwable unused) {
            return null;
        }
    }

    public static int getBackupDecoupleCoreVersion(Context context, String str) {
        try {
            return com.tencent.smtt.utils.a.b(new File(new File(com.tencent.smtt.utils.j.a(getPackageContext(context, str), 4)), "x5.tbs.decouple"));
        } catch (Throwable unused) {
            return 0;
        }
    }

    public static boolean getCoreDisabled() {
        return g;
    }

    public static boolean getCoreFormOwn() {
        return j;
    }

    public static String[] getCoreProviderAppList() {
        return new String[]{TbsConfig.APP_DEMO, TbsConfig.APP_WX, TbsConfig.APP_QQ, TbsConfig.APP_QZONE};
    }

    public static int getCoreShareDecoupleCoreVersion(Context context, String str) {
        Context packageContext = getPackageContext(context, str);
        if (packageContext != null) {
            return am.a().i(packageContext);
        }
        return 0;
    }

    public static String getHostCorePathAppDefined() {
        return c;
    }

    public static long getHostCoreVersions(Context context) {
        String[] coreProviderAppList;
        long sharedTbsCoreVersion;
        long sharedTbsCoreVersion2;
        long j2;
        long j3 = 0;
        for (String str : getCoreProviderAppList()) {
            if (str.equalsIgnoreCase(TbsConfig.APP_WX)) {
                sharedTbsCoreVersion2 = getSharedTbsCoreVersion(context, str);
                j2 = RealConnection.IDLE_CONNECTION_HEALTHY_NS;
            } else if (str.equalsIgnoreCase(TbsConfig.APP_QQ)) {
                sharedTbsCoreVersion2 = getSharedTbsCoreVersion(context, str);
                j2 = 100000;
            } else if (str.equalsIgnoreCase(TbsConfig.APP_QZONE)) {
                sharedTbsCoreVersion = getSharedTbsCoreVersion(context, str);
                j3 += sharedTbsCoreVersion;
            }
            sharedTbsCoreVersion = sharedTbsCoreVersion2 * j2;
            j3 += sharedTbsCoreVersion;
        }
        return j3;
    }

    public static Context getPackageContext(Context context, String str) {
        try {
            return context.createPackageContext(str, 2);
        } catch (PackageManager.NameNotFoundException unused) {
            return null;
        } catch (Exception e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public static int getSharedTbsCoreVersion(Context context, String str) {
        Context packageContext = getPackageContext(context, str);
        if (packageContext != null) {
            return am.a().j(packageContext);
        }
        return 0;
    }

    public static File getTbsShareFile(Context context, String str) {
        File s = am.a().s(context);
        if (s == null) {
            return null;
        }
        File file = new File(s, str);
        if (file.exists()) {
            return file;
        }
        try {
            file.createNewFile();
            return file;
        } catch (IOException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    static synchronized int h(Context context) {
        synchronized (TbsShareManager.class) {
            TbsLog.i("TbsShareManager", "readCoreVersionFromConfig #1");
            BufferedInputStream bufferedInputStream = null;
            try {
                File tbsShareFile = getTbsShareFile(context, "core_info");
                if (tbsShareFile == null) {
                    TbsLog.i("TbsShareManager", "readCoreVersionFromConfig #2");
                    return 0;
                }
                BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(tbsShareFile));
                try {
                    Properties properties = new Properties();
                    properties.load(bufferedInputStream2);
                    String property = properties.getProperty("core_version", "");
                    if ("".equals(property)) {
                        TbsLog.i("TbsShareManager", "readCoreVersionFromConfig #4");
                        try {
                            bufferedInputStream2.close();
                        } catch (Exception e2) {
                            e2.printStackTrace();
                        }
                        return 0;
                    }
                    TbsLog.i("TbsShareManager", "readCoreVersionFromConfig #3");
                    int max = Math.max(Integer.parseInt(property), 0);
                    try {
                        bufferedInputStream2.close();
                    } catch (Exception e3) {
                        e3.printStackTrace();
                    }
                    return max;
                } catch (Throwable th) {
                    bufferedInputStream = bufferedInputStream2;
                    th = th;
                    th.printStackTrace();
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (Exception e4) {
                            e4.printStackTrace();
                        }
                    }
                    TbsLog.i("TbsShareManager", "readCoreVersionFromConfig #5");
                    return -2;
                }
            } catch (Throwable th2) {
                th = th2;
            }
        }
    }

    public static boolean i(Context context) {
        try {
            if (e == 0) {
                findCoreForThirdPartyApp(context);
            }
            int i2 = e;
            if (i2 == 0) {
                TbsLog.addLog(TbsLog.TBSLOG_CODE_SDK_NO_SHARE_X5CORE, null, new Object[0]);
                return false;
            }
            if (c == null) {
                if (i2 != 0 && getSharedTbsCoreVersion(context, f) == e) {
                    return true;
                }
            } else if (i2 != 0 && am.a().a(c) == e) {
                return true;
            }
            if (l(context)) {
                return true;
            }
            TbsCoreLoadStat tbsCoreLoadStat = TbsCoreLoadStat.getInstance();
            tbsCoreLoadStat.a(context, TbsListener.ErrorCode.INFO_CORE_EXIST_NOT_LOAD, new Throwable("mAvailableCoreVersion=" + e + "; mSrcPackageName=" + f + "; getSharedTbsCoreVersion(ctx, mSrcPackageName) is " + getSharedTbsCoreVersion(context, f) + "; getHostCoreVersions is " + getHostCoreVersions(context)));
            d = null;
            e = 0;
            TbsLog.addLog(TbsLog.TBSLOG_CODE_SDK_CONFLICT_X5CORE, null, new Object[0]);
            QbSdk.a(context, "TbsShareManager::isShareTbsCoreAvailableInner forceSysWebViewInner!");
            return false;
        } catch (Throwable th) {
            th.printStackTrace();
            TbsLog.addLog(TbsLog.TBSLOG_CODE_SDK_UNAVAIL_X5CORE, null, new Object[0]);
            return false;
        }
    }

    public static boolean isThirdPartyApp(Context context) {
        Context context2;
        try {
            context2 = a;
        } catch (Throwable th) {
            TbsLog.i("TbsShareManager", "isThirdPartyApp error " + th.getMessage() + " ## " + th.getCause());
            th.printStackTrace();
        }
        if (context2 != null && context2.equals(context.getApplicationContext())) {
            TbsLog.i("TbsShareManager", "isThirdPartyApp return sIsThirdPartyApp is " + b);
            return b;
        }
        Context applicationContext = context.getApplicationContext();
        a = applicationContext;
        String packageName = applicationContext.getPackageName();
        String[] coreProviderAppList = getCoreProviderAppList();
        TbsLog.i("TbsShareManager", "isThirdPartyApp packageName is " + packageName);
        for (String str : coreProviderAppList) {
            TbsLog.i("TbsShareManager", "isThirdPartyApp appPackageName is " + str);
            if (packageName.equals(str)) {
                b = false;
                TbsLog.i("TbsShareManager", "isThirdPartyApp return false appPackageName is " + str);
                return false;
            }
        }
        b = true;
        TbsLog.i("TbsShareManager", "isThirdPartyApp return true ");
        return true;
    }

    public static boolean j(Context context) {
        return b(context, true);
    }

    private static boolean k(Context context) {
        String str = f;
        if (str == null) {
            return false;
        }
        return e == getSharedTbsCoreVersion(context, str) || e == getCoreShareDecoupleCoreVersion(context, f);
    }

    private static boolean l(Context context) {
        if (QbSdk.getOnlyDownload()) {
            return false;
        }
        String[] coreProviderAppList = getCoreProviderAppList();
        for (String str : coreProviderAppList) {
            int i2 = e;
            if (i2 > 0 && i2 == getSharedTbsCoreVersion(context, str)) {
                Context packageContext = getPackageContext(context, str);
                if (am.a().f(context)) {
                    d = am.a().b(context, packageContext).getAbsolutePath();
                    f = str;
                    return true;
                }
            }
        }
        for (String str2 : coreProviderAppList) {
            int i3 = e;
            if (i3 > 0 && i3 == getCoreShareDecoupleCoreVersion(context, str2)) {
                Context packageContext2 = getPackageContext(context, str2);
                if (am.a().f(context)) {
                    d = am.a().c(context, packageContext2).getAbsolutePath();
                    f = str2;
                    writeProperties(context, Integer.toString(e), f, d, Integer.toString(0));
                    return true;
                }
            }
        }
        return false;
    }

    private static boolean m(Context context) {
        if (context == null) {
            return false;
        }
        writeProperties(context, Integer.toString(0), "", "", Integer.toString(0));
        return true;
    }

    private static synchronized void n(Context context) {
        Throwable th;
        BufferedInputStream bufferedInputStream;
        File tbsShareFile;
        Context context2;
        synchronized (TbsShareManager.class) {
            if (k) {
                return;
            }
            try {
                tbsShareFile = getTbsShareFile(context, "core_info");
            } catch (Throwable th2) {
                th = th2;
                bufferedInputStream = null;
            }
            if (tbsShareFile == null) {
                return;
            }
            bufferedInputStream = new BufferedInputStream(new FileInputStream(tbsShareFile));
            try {
                Properties properties = new Properties();
                properties.load(bufferedInputStream);
                String property = properties.getProperty("core_version", "");
                if (!"".equals(property)) {
                    e = Math.max(Integer.parseInt(property), 0);
                }
                String property2 = properties.getProperty("core_packagename", "");
                if (!"".equals(property2)) {
                    f = property2;
                }
                String str = f;
                if (str != null && (context2 = a) != null) {
                    if (str.equals(context2.getPackageName())) {
                        j = true;
                    } else {
                        j = false;
                    }
                }
                String property3 = properties.getProperty("core_path", "");
                if (!"".equals(property3)) {
                    d = property3;
                }
                String property4 = properties.getProperty("app_version", "");
                if (!"".equals(property4)) {
                    i = property4;
                }
                g = Boolean.parseBoolean(properties.getProperty("core_disabled", "false"));
                k = true;
                try {
                    bufferedInputStream.close();
                } catch (Exception e2) {
                    e = e2;
                    e.printStackTrace();
                }
            } catch (Throwable th3) {
                th = th3;
                th.printStackTrace();
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (Exception e3) {
                        e = e3;
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public static void setHostCorePathAppDefined(String str) {
        c = str;
    }

    /* JADX WARN: Code restructure failed: missing block: B:304:0x036e, code lost:
        r11.c(r10, true);
     */
    /* JADX WARN: Removed duplicated region for block: B:290:0x0309 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:293:0x0315 A[Catch: all -> 0x03cc, TryCatch #6 {, blocks: (B:178:0x0003, B:180:0x001b, B:183:0x002b, B:185:0x0047, B:189:0x0056, B:194:0x006a, B:197:0x0078, B:199:0x0098, B:202:0x00a6, B:204:0x00ae, B:209:0x00cf, B:211:0x00d3, B:213:0x00df, B:223:0x0124, B:225:0x0130, B:227:0x0134, B:229:0x013c, B:232:0x015a, B:243:0x01b7, B:245:0x01bb, B:247:0x01c3, B:250:0x01e3, B:252:0x01f1, B:257:0x021e, B:288:0x0305, B:291:0x030b, B:293:0x0315, B:295:0x031f, B:298:0x032f, B:301:0x033b, B:303:0x0363, B:304:0x036e, B:305:0x0372, B:307:0x0378, B:310:0x0387, B:313:0x0392, B:315:0x03ba, B:264:0x025a, B:266:0x0260, B:268:0x0266, B:271:0x0286, B:273:0x0294, B:278:0x02c1, B:205:0x00bb, B:207:0x00c1, B:253:0x020f, B:274:0x02b2, B:233:0x016b, B:236:0x0189, B:214:0x00ee, B:217:0x00fa), top: B:325:0x0003 }] */
    /* JADX WARN: Removed duplicated region for block: B:341:0x03ca A[EDGE_INSN: B:341:0x03ca->B:318:0x03ca ?: BREAK  , SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static synchronized void writeCoreInfoForThirdPartyApp(android.content.Context r10, int r11, boolean r12) {
        /*
            Method dump skipped, instructions count: 977
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.TbsShareManager.writeCoreInfoForThirdPartyApp(android.content.Context, int, boolean):void");
    }

    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:101:0x00c2 -> B:146:0x00e4). Please submit an issue!!! */
    public static void writeProperties(Context context, String str, String str2, String str3, String str4) {
        BufferedOutputStream bufferedOutputStream;
        File tbsShareFile;
        Properties properties;
        int i2;
        BufferedOutputStream bufferedOutputStream2;
        TbsLog.i("TbsShareManager", "writeProperties coreVersion is " + str + " corePackageName is " + str2 + " corePath is " + str3);
        StringBuilder sb = new StringBuilder();
        sb.append("writeProperties -- stack: ");
        sb.append(Log.getStackTraceString(new Throwable("#")));
        TbsLog.i("TbsShareManager", sb.toString());
        BufferedInputStream bufferedInputStream = null;
        try {
            try {
                tbsShareFile = getTbsShareFile(context, "core_info");
            } catch (Throwable th) {
                th = th;
                bufferedOutputStream = null;
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        if (tbsShareFile == null) {
            TbsDownloadConfig.getInstance(a).setDownloadInterruptCode(-405);
            return;
        }
        BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(tbsShareFile));
        try {
            properties = new Properties();
            properties.load(bufferedInputStream2);
            try {
                i2 = Integer.parseInt(str);
            } catch (Exception unused) {
                i2 = 0;
            }
            if (i2 != 0) {
                properties.setProperty("core_version", str);
                properties.setProperty("core_disabled", String.valueOf(false));
                properties.setProperty("core_packagename", str2);
                properties.setProperty("core_path", str3);
                properties.setProperty("app_version", str4);
            } else {
                properties.setProperty("core_disabled", String.valueOf(true));
            }
            bufferedOutputStream2 = new BufferedOutputStream(new FileOutputStream(tbsShareFile));
        } catch (Throwable th2) {
            th = th2;
            bufferedOutputStream = null;
            bufferedInputStream = bufferedInputStream2;
        }
        try {
            properties.store(bufferedOutputStream2, (String) null);
            k = false;
            TbsDownloadConfig.getInstance(a).setDownloadInterruptCode(-406);
            try {
                bufferedInputStream2.close();
            } catch (Exception e3) {
                e3.printStackTrace();
            }
            bufferedOutputStream2.close();
        } catch (Throwable th3) {
            bufferedInputStream = bufferedInputStream2;
            bufferedOutputStream = bufferedOutputStream2;
            th = th3;
            try {
                th.printStackTrace();
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (Exception e4) {
                        e4.printStackTrace();
                    }
                }
                if (bufferedOutputStream != null) {
                    bufferedOutputStream.close();
                }
            } catch (Throwable th4) {
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (Exception e5) {
                        e5.printStackTrace();
                    }
                }
                if (bufferedOutputStream != null) {
                    try {
                        bufferedOutputStream.close();
                    } catch (Exception e6) {
                        e6.printStackTrace();
                    }
                }
                throw th4;
            }
        }
    }
}
